//! Performs the basic internal operations associated with creating a new user.

use std::sync::Arc;

use tracing::*;

use aspect_codec::prelude::*;
use aspect_db_common::{job_queue::prelude::*, user::UserDatastore};

pub struct CreateUserJob {
    user_db: Arc<UserDatastore>,
}

#[derive(Clone, Debug)]
pub struct CreateUserJobData {
    username: String,
}

aspect_codec::inst_struct_codec! {
    CreateUserJobData {
        username: String
    }
}

impl Job for CreateUserJob {
    type Payload = CreateUserJobData;

    fn type_name(&self) -> &str {
        "create_user"
    }

    fn exec_job_payload(
        &self,
        job_meta: &JobMeta,
        payload: &Self::Payload,
    ) -> impl Future<Output = Result<(), JobError>> + Sync + Send {
        async {
            let username = &payload.username;
            info!(%username, "creating user (job)");
            Ok(())
        }
    }
}
